//
//  RNRouter.m
//  BCRouteKit
//
//  Created by Basic on 2021/4/21.
//

#import "RNRouter.h"
#import <React/RCTBridgeModule.h>
//#import <BCEventBus/BCEventBusKit.h>
//#import <BCFoundation/BCRNModule.h>
#import "BCRouteKit.h"


///主线程安全调用
#define rnsafe_dispatch_async(block) { \
    if(block){\
        if ([NSThread isMainThread]) {\
            block();\
        } else {\
            dispatch_async(dispatch_get_main_queue(), block);\
        }\
    }\
}\


@interface RNRouter() <RCTBridgeModule>

@end


@implementation RNRouter


//MARK: - RCTBridgeModule
RCT_EXPORT_MODULE(ZHRouterModule);
//RCT_EXPORT_PRE_REGISTERED_MODULE(ZHRouterModule);

///退出 RN Screen 页面，跳转到 native 页面
RCT_EXPORT_METHOD(popToNative) {
    rnsafe_dispatch_async(^{
        [[BCRouter sharedInstance] popRoute:true];
    });
//    callback(@[[NSNull null]]);
}

///打开 native web 页面
RCT_EXPORT_METHOD(openWeb:(NSString *)url params:(NSDictionary *)params) {
    rnsafe_dispatch_async(^{
        [BCRouter.shared pushRoute:kZHRouteH5URL(url) extData:params];
    });
}

@end


